﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Logistics_Service.DTO;
using System.Data;

namespace Logistics_Service.DAO
{
    public class DangNhapDAO
    {
        public KhachHangDTO LoginKH(string username,string pass)
        {
            KhachHangDTO kh = new KhachHangDTO();
            DataTable tb = new DataTable();
            string sql = string.Format("select * from KhachHang where UserName='{0}' and MatKhau='{1}'", username, pass);
            DataProvider ds = new DataProvider();
            tb = ds.ExecuteQuery(sql);
            if (tb.Rows.Count != 0)
            {
                kh.Ma = tb.Rows[0]["Ma"].ToString();
                kh.Ten = tb.Rows[0]["Ten"].ToString();
                kh.UserName = tb.Rows[0]["UserName"].ToString();
                kh.MatKhau = tb.Rows[0]["MatKhau"].ToString();
                kh.CMND = tb.Rows[0]["CMND"].ToString();
                kh.SDT = tb.Rows[0]["SDT"].ToString();
                kh.Email = tb.Rows[0]["Email"].ToString();
                kh.NgayDangKy = DateTime.Parse(tb.Rows[0]["NgayDangKy"].ToString());
                kh.NgaySinh = DateTime.Parse(tb.Rows[0]["NgaySinh"].ToString());
                kh.DiaChi = tb.Rows[0]["DiaChi"].ToString();
                kh.DaXoa = bool.Parse(tb.Rows[0]["DaXoa"].ToString());
                kh.XacNhan = bool.Parse(tb.Rows[0]["XacNhan"].ToString());
            }
            else
            {
                kh.Ma = "0";
                kh.Ten = "null";
                kh.UserName = "null";
                kh.MatKhau = "null";
                kh.CMND = "null";
                kh.SDT = "null";
                kh.Email = "null";
                kh.NgayDangKy =DateTime.Today;
                kh.NgaySinh = DateTime.Today;
                kh.DiaChi = "null";
                kh.DaXoa = true;
                kh.XacNhan = true;
            }
            return kh;
        }
    }
}